<?php
class RolBehavior extends CActiveRecordBehavior {
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function searchPorEmpresa()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.
		$owner = $this->getOwner();
		
		$criteria=new CDbCriteria;
	
		$criteria->compare('nombre',$owner->nombre,true);
		$criteria->compare('descripcion',$owner->descripcion,true);
		$criteria->compare('activo',1,true);
		
		$empresa=UsuarioHelper::obtenerEmpresaUsuarioAutenticado();
		if($empresa){
			$criteria->compare('empresa_id',$empresa->id);
		}else{
			$criteria->compare('empresa_id',$owner->empresa_id);
		}
		
		
		return new CActiveDataProvider($owner, array(
				'criteria'=>$criteria,
		));
	}
	
}